package liumengbaio.lolzhangyoubao.Activity.utils;


import android.content.Context;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.SummonerSkillsInfo;

/**
 * 召唤师技能的获取方法
 * Created by lanouhn on 16/9/1.
 */
public class SummonerSkillsUtils {

    public static List<SummonerSkillsInfo> getSummonerSkillsInfoList(Context mContext) {
        List<SummonerSkillsInfo> lssi = new ArrayList<>();
        for (int i = 0; i < lssi.size(); i++) {
            SummonerSkillsInfo ssi = (SummonerSkillsInfo) getSummonerSkillsInfoList(mContext);
            lssi.add(ssi);
        }
        return lssi;
    }

    /**
     * 获取对应ID的召唤师技能信息
     *
     * @param mContext
     * @return
     */
    public static List<SummonerSkillsInfo> getSummonerSkillsInfo(Context mContext) {

        List<SummonerSkillsInfo> lssi = new ArrayList<>();
        try {
            InputStream is = mContext.getAssets().open("skills/summoner_skills.json");
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            is.close();

            String text = new String(buffer, "UTF-8");
            JSONObject mObject = new JSONObject(text);
            JSONArray array = mObject.getJSONArray("data");

            for (int i = 0; i < array.length(); i++) {
                SummonerSkillsInfo ssi = new SummonerSkillsInfo();
                JSONObject object1 = array.getJSONObject(i);
                ssi.setPic_url(object1.getString("pic_url"));
                ssi.setName(object1.getString("name"));
                ssi.setCode(object1.getString("cold"));
                ssi.setDesc(object1.getString("desc"));
                ssi.setLevel(object1.getString("level"));
                ssi.setPic(object1.getString("pic"));
                lssi.add(ssi);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lssi;
    }

}
